
<div class="templatemo-content-wrapper">
	<div class="templatemo-content">
		<ul class="nav nav-tabs mytabs">
		  <li><a href="<?=site_url()?>/suser/index">特价用户列表</a></li>
		  <li class="active" role="presentation"><a href="<?php echo site_url('suser/add')?>"><i class="fa fa-plus"></i> 添加特价用户</a></li>
		</ul>
		<div class="row">
			<div class="col-md-12">
				<div class="table-responsive">
					<form role="form" id="templatemo-preferences-form"
						onsubmit="return false;">
						<div class="row">
							<div class="col-md-6 margin-bottom-15">
								<label for="firstName" class="control-label">饭店名称</label> 
								<input type="text" class="form-control" id="name" value="">
								<input type="hidden" id="userid" value="">	
						    </div>
						</div>
						<div class="row templatemo-form-buttons">
							<div class="col-md-12">
								<button type="submit" class="btn btn-primary" id="submit_btn">添加</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
	$(document).ready(function() {
		$("#name").autocomplete({
			minLength:1,
			source:function(request,response){
				/*var term = request.term;
				if ( term in cache ) {
         			 response( cache[ term ] );
         			 return;
       			 }*/
       			 $.ajax({
                    url:'<?php echo site_url('user/getUsers')?>',
                    type : "post",
                    dataType: "json",
                    data:{
                        name: request.term
                    },
                    success: function( data ) {
                        //cache[ term ] = data;
                        response($.map(data, function(item) {
    		            return {
    		                  label: item.shopname+'-'+item.id,
    		                  value: item.shopname,
    		                  userid:item.id
    		             }
    		         }));
                    }
                });
			},
			select: function( event, ui ) {
        		$( "#userid" ).val( ui.item.userid );
      		}
		});
		$("#submit_btn").click(function() {
			var userid = $("#userid").val();
			$.ajax({
				url : '<?php echo site_url('suser/save')?>',
				type : "post",
				async : true,
				data : {
					'userid' : userid
				},
				dataType : "json",
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						window.location.reload();
					}else{
						alert(data.msg);
					}
				}
			});
		});
	}); 
</script>